﻿using System;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Windows;

using SynergyControls;
using SynergyLib.DSP;
using SharpDX.XAudio2;

namespace XAudio2Controls
{
    public class SchroederPanel : EffectsPanel, IEffectParams
    {
        public float CombGain
        {
            get
            { return DialAngle1 / 360; }
        }

        public float AllpassGain
        {
            get
            { return DialAngle2 / 360; }
        }
        public float f
        {
            get { return DialAngle3 / 360; }
        }
        public float DelayMS
        {
            get { return DialAngle4 / 360; }
        }

        public SchroederEffect shroedin { get; set; }

        static SchroederPanel()
        {
            DefaultStyleKeyProperty.OverrideMetadata(typeof(SchroederPanel), new FrameworkPropertyMetadata(typeof(EffectsPanel)));
        }
        public SchroederPanel(SubmixVoice submixer, Collection<EffectDescriptor> fxChainReference)
        {
            FxChain = fxChainReference;
            EffectParams = this;
            effectType = EffectTypes.Schroeder;
            Submixer = submixer;            
            this.Effect = new SchroederEffect();
            shroedin = (SchroederEffect)Effect;
            this.effectDescriptor = new EffectDescriptor(Effect);
        }

        protected override void UpdateParameters()
        {
            SchroederParams prms = new SchroederParams()
            {
                CombGain = this.Param1,
                AllpassGain = this.Param2,
                f = this.Param3,
                DelayMs = this.Param4,
            };
            shroedin.Parameters = prms;
        }

        #region IEffectParams
        public float Param1
        {
            get
            {
                ParamLabel1Content = GetParam1Readout();
                return CombGain;
            }
        }
        public float Param2
        {
            get
            {
                ParamLabel2Content = GetParam2Readout();
                return AllpassGain;
            }
        }
        public float Param3
        {
            get
            {
                ParamLabel3Content = GetParam3Readout();
                return f;
            }
        }
        public float Param4
        {
            get
            {
                ParamLabel4Content = GetParam4Readout();
                return DelayMS;
            }
        }

        public string ParamName1
        {
            get
            {
                return "f";
            }
        }
        public string ParamName2
        {
            get
            {
                return "CombGain";
            }
        }
        public string ParamName3
        {
            get
            {
                return "AllpassGain";
            }
        }
        public string ParamName4
        {
            get
            {
                return "Delay";
            }
        }

        public string GetParam1Readout()
        {
            return (Math.Round(CombGain, 2)).ToString();
        }
        public string GetParam2Readout()
        {
            return (Math.Round(AllpassGain, 2)).ToString();
        }
        public string GetParam3Readout()
        {
            return (Math.Round(f, 2)).ToString();
        }
        public string GetParam4Readout()
        {
            return Math.Round(DelayMS, 2).ToString();
        }
        #endregion IEffectParams
    }
}
